Repository navigation
Preserve indexed coordinates with differing names in to_dataframe (#10851) - #11935
Open
uvcode01-max wants to merge 2 commits into
Open
uvcode01-max wants to merge 2 commits into
uvcode01-max wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a regression from #10671 where
Dataset.to_dataframe()previously excluded all variables present inself.xindexesfrom the output DataFrame columns (k not in self.xindexes), regardless of whether those variables actually become part of the DataFrame index.When a coordinate has an index whose name differs from its dimension (e.g. created via
.set_xindex("pf")on dimensionpos), the DataFrame index is constructed from the dimension (pos), butpfwas excluded fromcolumns_in_orderand silently lost.Following the architecture guidance from @headtr1ck in #11025:
The column exclusion now only filters out the dimensions and the levels that actually form the DataFrame index:
This preserves indexed coordinates with differing names (e.g.
pf) as columns while correctly excluding index levels in MultiIndex scenarios.Checklist
._to_dataframe()when name different from dimension name #10851 (supersedes inactive fix: Include index coordinates in to_dataframe when name differs from dimension (Fixes #10851) #11025)xarray/tests/test_dataset.py(test_to_dataframe_indexed_coord_differing_name)doc/whats-new.rstAI Disclosure
Tools: AI assistant used to locate the regression and format test cases.